package com.example.carrierapp.ui.adapter;

import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.carrierapp.bean.tender.TenderListBean;
import com.example.carrierapp.ui.view.recycleview.XRecyclerView;
import com.example.carrierapp.util.LogUtil;
import com.example.lb.fingerdemo.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TenderNoAdatpter extends XRecyclerView.Adapter<TenderNoAdatpter.ViewHolder> {
    private List<TenderListBean.TenderListInfo> mList = new ArrayList();
    private int mClickIndex;
    private boolean mShowPrice;
    public TenderNoAdatpter(boolean showPrice) {
        mShowPrice=showPrice;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_tender_no, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TenderListBean.TenderListInfo info = mList.get(position);
        holder.bindData(info, mShowPrice);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void addDataNotClear(List<TenderListBean.TenderListInfo> list) {
        if (list != null && list.size() > 0) {
            mList.addAll(list);
            notifyDataSetChanged();
        }
    }

    public void addData(List<TenderListBean.TenderListInfo> list) {
        if (list != null && list.size() > 0) {
            mList.clear();
            mList.addAll(list);
            notifyDataSetChanged();
        }
    }

    public void clear() {
        mList.clear();
        notifyDataSetChanged();
    }


    public class ViewHolder extends XRecyclerView.ViewHolder {

        @BindView(R.id.tv_tender_code)
        TextView mTvCode;
        @BindView(R.id.tv_tend_outcar)
        TextView mTvOutcar;
        @BindView(R.id.tv_tend_incar)
        TextView mTvIntcar;
        @BindView(R.id.tv_tend_goods)
        TextView mTvGoods;
        @BindView(R.id.tv_tend_volume)
        TextView mTvVolume;
        @BindView(R.id.tv_tend_fee)
        TextView mTvFee;
        @BindView(R.id.tv_tend_feeno)
        TextView mTvFeeno;
        @BindView(R.id.tv_tend_price)
        TextView mTvPrice;
        @BindView(R.id.tv_tend_price_title)
        TextView mTvPriceTitle;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void bindData(TenderListBean.TenderListInfo info, boolean mShowPrice) {
            if (info == null) {
                LogUtil.d("info is null");
                return;
            }
            mTvPrice.setVisibility(mShowPrice?View.VISIBLE:View.GONE);
            mTvPriceTitle.setVisibility(mShowPrice?View.VISIBLE:View.GONE);

            mTvCode.setText("资源编码："+info.bidCode);
            mTvIntcar.setText(info.startCity);
            mTvOutcar.setText(info.endCity);
            mTvGoods.setText(info.proName);
            mTvVolume.setText(info.proNum+info.unitName);
            mTvFee.setText(info.offer+"元/"+info.unitName);
            mTvFeeno.setText(info.unTaxOffer+"元/"+info.unitName+"（税率"+info.taxRate*100+"%）");
            mTvPrice.setText(info.winOffer+"元/"+info.unitName);
        }
    }
}
